//
//  ViewController.swift
//  HelloTagListView
//
//  Created by Chen,Meisong on 2020/11/7.
//

import UIKit
import SnapKit

class ViewController: UIViewController {
    // MARK: Data
    var tagListViewHeightConstraint: SnapKit.Constraint?
    // MARK: View
    private lazy var topView: UIView = {
        var view = UIView()
        view.backgroundColor = .red
        
        return view
    }()
    
    private lazy var tagListView: TagListView = {
        var view = TagListView()
        
        return view
    }()
    
    private lazy var bottomView: UIView = {
        var view = UIView()
        view.backgroundColor = .blue
        
        return view
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addSubViews()
        makeLayout()
        
//        tagListView.configDatas(["111", "2222222222222222", "3333"])
        DispatchQueue.main.async { [weak self] in
            guard let self = self else { return }
            self.tagListView.snp.remakeConstraints { (maker) in
                maker.left.right.equalTo(self.view)
                maker.top.equalTo(self.topView.snp.bottom)
                maker.bottom.equalTo(self.bottomView.snp.top)
                maker.height.equalTo(self.tagListView.collectionView.collectionViewLayout.collectionViewContentSize.height)
            }
        }
        
    }
}

extension ViewController {
    private func addSubViews() {
        view.addSubview(topView)
        view.addSubview(tagListView)
        view.addSubview(bottomView)
    }
    
    private func makeLayout() {
        topView.snp.makeConstraints { (maker) in
            maker.left.right.top.equalTo(view)
            maker.height.equalTo(100)
        }
        tagListView.snp.makeConstraints { (maker) in
            maker.left.right.equalTo(view)
            maker.top.equalTo(topView.snp.bottom)
            maker.bottom.equalTo(bottomView.snp.top)
        }
        bottomView.snp.makeConstraints { (maker) in
            maker.left.right.bottom.equalTo(view)
        }
    }
}

